package org.ttitfly.ttcore.system;

import org.springframework.context.ApplicationContext;
import org.springframework.util.Assert;

/**
 * 平台，为各级提供spring的getbean的方法
 *
 * @author mahaibo
 */
public class Platform {
	private static Platform ourInstance = new Platform();

	public static Platform getInstance() {
		return ourInstance;
	}

	private Platform() {
	}

	private ApplicationContext applicationContext = null;

	public void setApplicationContext(ApplicationContext applicationContext) {
		this.applicationContext = applicationContext;
	}

	/**
	 * 根据BeanName获得Bean
	 *
	 * @param beanName sping配置的id
	 * @return 符合条件的bean
	 */
	public Object getBean(String beanName) {
		Assert.hasText(beanName);
		return this.applicationContext.getBean(beanName);
	}

	// 平台部署的根物理路径
	private String WebPath;

	/**
	 * 获得平台部署的根物理路径
	 *
	 * @return 根物理路径
	 */
	public String getWebPath() {
		return WebPath;
	}

	/**
	 * 设置根物理路径
	 *
	 * @param webPath 根物理路径
	 */
	public void setWebPath(String webPath) {
		WebPath = webPath;
	}
}
